var http = require('http')
var options = {  
    host: 'localhost',  
    port: 8080,  
    path: '/',  
    method: 'GET',  
    headers: {
	host: 'www.baidu.com',
	connection: 'keep-alive',
	'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36',
	accept: '*/*',
	referer: 'http://www.baidu.com/',
	'accept-encoding': 'gzip, deflate, sdch',
	'accept-language': 'en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4',
    }  
};
//以下是接受数据的代码
var body = '';
var req = http.request(options, function(res) {
  console.log("Got response: " + res.statusCode);
  res.on('data',function(d){
  body += d;
 }).on('end', function(){
  console.log(res.headers)
  console.log(body)
 });

}).on('error', function(e) {
  console.log("Got error: " + e.message);
})
req.end();